import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:industry_net/base/common/location/state.dart';
import 'package:industry_net/base/common/util.dart';
import 'package:industry_net/base/component/component.dart';
import 'package:industry_net/pages/msg/map_earth/controller.dart';

class MapEarthPage extends GetView<MapEarthController> {
  const MapEarthPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: detailAppBar(context),
        body: GetBuilder<MapEarthController>(builder: (logic) {
          var paintState = logic.state.locationCtrl.state.paintState;
          return Container(
            child: Stack(
              children: [
                logic.state.map ?? const SizedBox(),
                Positioned(
                  left: gap15,
                  right: gap15,
                  height: 50.r,
                  bottom: SizeFit.safeBottom + 30.r,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      Visibility(
                        visible: paintState.value == MapPaintState.idle,
                        child: InkWell(
                          onTap: controller.backToOrigin,
                          child: Container(
                            alignment: Alignment.center,
                            width: 44.r,
                            height: 44.r,
                            decoration: BoxDecoration(
                              color: ColorsUtil.white,
                              borderRadius: BorderRadius.circular(22.r),
                            ),
                            child: loadImage(
                                url: 'location_curr.png'.imgPathMsg,
                                width: 24.r,
                                height: 24.r),
                          ),
                        ),
                      ),
                      InkWell(
                        onTap: () {
                          if (paintState.value == MapPaintState.idle) {
                            logic.actionPainting();
                          } else if (paintState.value ==
                              MapPaintState.painting) {
                            logic.actionRevokePaint();
                          } else {
                            logic.actionResetPaint();
                          }
                        },
                        child: Container(
                          width: 120.r,
                          height: 50.r,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              color: ColorsUtil.blue,
                              borderRadius: BorderRadius.circular(25.r)),
                          child: Text(
                            paintState.value == MapPaintState.idle
                                ? '开始绘制'
                                : paintState.value == MapPaintState.painting
                                    ? '撤销'
                                    : '重新绘制',
                            style: pfMediumStyle(
                                color: ColorsUtil.white, fontSize: font16),
                          ),
                        ),
                      ),
                      Visibility(
                        visible: paintState.value != MapPaintState.idle,
                        child: InkWell(
                          onTap: () {
                            if (paintState.value == MapPaintState.painting) {
                              logic.actionCancelPaint();
                            } else {
                              logic.actionFinishPaint();
                            }
                          },
                          child: Container(
                            width: 120.r,
                            height: 50.r,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                color: ColorsUtil.blue,
                                borderRadius: BorderRadius.circular(25.r)),
                            child: Text(
                              paintState.value == MapPaintState.painting
                                  ? '取消'
                                  : '保存',
                              style: pfMediumStyle(
                                  color: ColorsUtil.white, fontSize: font16),
                            ),
                          ),
                        ),
                      ),
                      Visibility(
                        visible: paintState.value == MapPaintState.idle,
                        child: InkWell(
                          onTap: controller.switchMapType,
                          child: Container(
                            alignment: Alignment.center,
                            width: 44.r,
                            height: 44.r,
                            decoration: BoxDecoration(
                              color: ColorsUtil.white,
                              borderRadius: BorderRadius.circular(22.r),
                            ),
                            child: loadImage(
                                url: controller
                                            .state.locationCtrl.state.mapType ==
                                        MapType.normal
                                    ? 'map_normal.png'.imgPathMsg
                                    : 'map_wx.png'.imgPathMsg,
                                width: 24.r,
                                height: 24.r),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          );
        }));
  }
}
